#!/bin/bash 
set -e

TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage3}
SRC=${SRC:-/sources}

name=openssl
version=1.1.1j

rm -fr $TMP
rm -rf $TMP
mkdir -p $TMP $LOG

tar xf $SRC/$name-$version.tar.gz -C $TMP

{ time \
   {

    cd $TMP/$name-$version
    
	./config --prefix=/usr         \
			 --openssldir=/etc/ssl \
			 --libdir=lib          \
			 shared                \
			 zlib-dynamic
    
    make

	sed -i '/INSTALL_LIBS/s/libcrypto.a libssl.a//' Makefile
	make MANSUFFIX=ssl install

	mv -v /usr/share/doc/openssl /usr/share/doc/$name-$version

	cp -vfr doc/* /usr/share/doc/$name-$version

    }
} 2>&1 | tee $name.log
    
[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
